package com.example.bbs.agent.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 代理类
 * author: VC
 * create: 2021/7/16 9:34
 * version: 1.0.0
 */
public class ObjectProxy implements InvocationHandler {
    //真实对象(被代理对象,委托对象)
    private Object target;

    public ObjectProxy(Object target) {
        this.target = target;
    }

    public void setTarget(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy,
                         Method method,
                         Object[] args) throws Throwable {
        System.out.println("调用方法前");
        Object val = method.invoke(target, args);
        System.out.println("调用方法后");
        return val;
    }
}
